//MISC Func

function sec2time(sec){ 
    dt = new Date(); 
    dt.setTime(sec*1000); 
    return dt.getUTCHours()+":"+dt.getUTCMinutes()+":"+dt.getUTCSeconds(); 
} 
//*********************BOT ENGINE

function BotEngine(){
	t = {}
	t.player = {
		gold:0,
		kri :0,
		exp :0,
		dozor : {
			time:0
		}
	}
	
	t.timers = {
		dozor :{
			id:0,
			end:0
		},
		fight :{
			id:0,
			end:0
		},
		mine:{
			id:0,
			end:0
		},
		monster:{
			id:0,
			end:0
		},
	}
	
	t.settings = {
		dozor: true,
		fight: true,
		mine : true,
		fight_base : 2
	}
	
	t.farmed = {
		gold:0,
		kri:0, 
		mine:0
	}
	
	t.getinfo = function(){
		function ok(r){
			t.player.dozor.time = r.watch.available_interval;
		}
		API.call("fight.getInfo",{},ok);
		t.player.gold = PLAYER.money.getInfo('money1');
		t.player.kri = PLAYER.money.getInfo('money2');
	}
	
	t.loop = function(){
		
	}
	
	t.init = function(){
		t.getinfo();
		if (PLAYER.work.getInfo('work_type')!=0){
			tend = PLAYER.work.getInfo('work_end')*1000-Date.now()+10000;
			console.log('Working. Waiting for end.', sec2time(tend/1000));
			setTimeout(t.loop, tend);
		}
	
	}
	return t;
}
BOT = BotEngine()